'use strict';
const {
	verifyToken
} = require("wx-common")

exports.main = async (event, context) => {
	const db = uniCloud.database()
	const dbcmd = db.command

	const payload = event.token ? verifyToken(event.token) : null

	if (payload && payload.openid) {
		const res = await db.collection('bookShelf').where({
			id: dbcmd.eq(event.id)
		}).get()
		if (res.affectedDocs <= 0) {
			return {
				code: 200,
				data: {}
			}
		} else {
			return {
				code: 200,
				data: res.data[0]
			}
		}
	} else {
		return payload
	}

};
